#ifndef INSTRUCTION_MEM_H
#define INSTRUCTION_MEM_H
#include"instruction.h"
#include<unordered_map>
#include<string>
#include<iostream>

class Instruction_Mem {
public:
    Instruction_Mem() {
        this->instruction_memory = new std::unordered_map<addr_size_t, instr_unit*>();
        this->instruction_memory->reserve(4096);
        this->function_list = new std::unordered_map<std::string, addr_unit*>();
        this->function_list->reserve(1024);
    }
    ~Instruction_Mem() {
        delete instruction_memory;
        delete function_list;
    }

    //对外暴露的API
    bool store_instruction(addr_size_t addr, instruction* instr, int para_nums, addr_size_t head_addr);
    instr_unit* get_instr(addr_size_t addr);
    bool store_function(std::string func_name, addr_size_t head_addr, addr_size_t end_addr);
    addr_unit* get_func(std::string func_name);

private:
    //先考虑使用hashmap来实现 指令地址->指令信息 的映射
    //TODO: 后续可以考虑使用malloc空间并线性映射的方式来实现，并对比性能
    std::unordered_map<addr_size_t, instr_unit*>* instruction_memory;
    std::unordered_map<std::string, addr_unit*>* function_list;
};

#endif //INSTRUCTION_MEM_H
